# -*- coding: utf-8 -*-
from datetime import timedelta
from jms_hi.dwd.tms.dwd_tmsnew_shipment_stop_union_base_hi import jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi
from jms_hi.dwd.tms.dwd_tmsnew_shipment_union_base_hi import jms_dwd__dwd_tmsnew_shipment_union_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_loading_base_hi import jms_dwd__dwd_tab_barscan_loading_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_unloading_base_hi import jms_dwd__dwd_tab_barscan_unloading_base_hi
from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_hi_dm__dm_shipment_stop_diff_unloading_detail_ht = SparkSqlOperator(
    task_id='jms_hi_dm__dm_shipment_stop_diff_unloading_detail_ht',
    email=['shenjiaming@jtexpress.com','yl_bigdata@yl-scm.com'],
    depends_on_past=True,
    pool_slots=5,
    master='yarn',
    name='jms_hi_dm__dm_shipment_stop_diff_unloading_detail_ht_{{ execution_date | cst_ds_nodash }}',
    sql='jms_hi/dm/dm_shipment_stop_diff_unloading_detail_ht/execute.hql',
    driver_memory='4G' , 
    executor_memory='5G' , 
    executor_cores=4 , 
    num_executors=10 , 
    yarn_queue='pro',
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 12 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '2G' , 
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 5000,
              'hive.exec.max.dynamic.partitions': 30000,
              },
    execution_timeout=timedelta(minutes=60),
)

jms_hi_dm__dm_shipment_stop_diff_unloading_detail_ht << [
    jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi,
    jms_dwd__dwd_tmsnew_shipment_union_base_hi,
    jms_dwd__dwd_tab_barscan_loading_base_hi,
    jms_dwd__dwd_tab_barscan_unloading_base_hi,
    jms_dim__dim_network_whole_massage
]
